home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0009_Re: Mem.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.7 KB  |  111 lines

  1. {
  2.  BZ> I was wondering if anyone has, or would mind writing a assembler
  3.  BZ> version of the Mem, MemW, and MemL functions.  Delphi does not
  4.  BZ> include these routines and I would really like to get them back.
  5.  
  6. here is an asm of mem.. you can modify it for memw and meml.. }
  7.  
  8. procedure(segment_,offset_: word; variable : byte); assembler;
  9. asm
  10.   mov ax,segment_
  11.   push ax
  12.   mov di,offset_
  13.   pop es
  14.   mov es:byte ptr [di],variable
  15. end;
  16.  
  17. {Actually, they are built in arrays.  Since pascal does not allow
  18. operator overloading, this is as close as you can get: }
  19.  
  20. function ReadMem (address : longint) : byte; assembler;
  21. asm
  22.   les di, address;
  23.   mov al, es:[di];
  24. end;
  25.  
  26. procedure WriteMem (address : longint; val : byte); assembler;
  27. asm
  28.   les di, address;
  29.   mov al, val;
  30.   stosb;
  31. end;
  32.  
  33. function ReadMemW (address : longint) : word; assembler;
  34. asm
  35.   les di, address;
  36.   mov ax, es:[di];
  37. end;
  38.  
  39. procedure WriteMemW (address : longint, val : word); assembler;
  40. asm
  41.   les di, address
  42.   mov ax, val;
  43.   stosw;
  44. end;
  45.  
  46. function ReadMemL (address : longint) : longint; assembler;
  47. asm
  48.   les di, address;
  49.   mov dx, word ptr es:[di];
  50.   mov ax, word ptr es:[di + 1];
  51. end;
  52.  
  53. procedure WriteMemL (address : longint, val : longint); assembler;
  54. asm
  55.   les di, address;
  56.   mov bx, offset val;
  57.   mov ax, word ptr [bx]
  58.   stosw;
  59.   mov ax, word ptr [bx + 1];
  60.   stosw;
  61. end;
  62.  
  63. For these, address is segment in high word, offset in low word.  To get
  64. a segment into the high word, shift it left by 8.  For example, to store
  65. the VGA video segment, you would do:
  66. address := $A000 SHL 8;
  67. Then just add the offset:
  68. address := address + youroffset;
  69.  
  70. You may also use a pointer as the address (Pascal stores pointers in the
  71. proper format).
  72.  
  73. Mike Phillips
  74. INTERNET:  phil4086@utdallas.edu
  75.  
  76.  
  77. GARY KING
  78.  
  79. PROCEDURE write_byte(segm,offs : word; val : byte);assembler;
  80. asm
  81. mov es,[segm]
  82. mov di,offs
  83. mov al,byte
  84. mov es:[di],al
  85. end;
  86.  
  87. PROCEDURE write_word(segm,offs,val : word);assembler;
  88. asm
  89. mov es,[segm]
  90. mov di,offs
  91. mov ax,val
  92. mov es:[di],ax
  93. end;
  94.  
  95. PROCEDURE write_long(segm,offs : word; val : longint);assembler;
  96. asm
  97. mov es,[segm]
  98. db $66; mov di,word ptr offs {converts to : mov edi,dword ptr offs}
  99. db $66; mov ax,word ptr val {converts to : mov eax, dword ptr val}
  100. db $66; mov es:[di],word ptr ax {to : mov es:[edi],dword ptr eax}
  101. end;
  102.  
  103. see, nothing to it.  no push'es or pop's.  Note : I'm not sure that the
  104. write_long will work, but I'm 99.5% sure it will (I'm not sure if the db $66
  105. converts di to edi or not, but I doubt that is matters...).  Everything else
  106. is guaranteed to work.  The write_long will require a 386 or better to run on,
  107. though.  Note : this can be modified into a putpixel fairly easily.
  108.  
  109. Gary
  110.  
  111.